<template>
  <view class="store-list">
    <scroll-view scroll-y @scrolltolower="loadMore">
      <view class="empty" v-if="isEmpty">
        <text>暂无数据</text>
      </view>
      <uni-list v-if="!isEmpty">
        <uni-list-item show-arrow clickable :title="data.wName" v-for="(data, index) in dataList" :key="index" @click="dataSelect(data)" />
      </uni-list>
    </scroll-view>
  </view>
</template>

<script>
  import { getStoreDataList } from '../../api/device/fitting';
  
  export default {
    name: 'StoreList',
    components: {},
    props: {},
    data() {
      return {
        isEmpty: false,
        dataList: [],
        isFinish: false,
        pageData: {
          pageNum: 1,
          pageSize: 20,
        },
      };
    },
    mounted() {
    },
    created() {
      this.getData();
    },
    methods: {
      async getData() {
        const param = { ...this.pageData };
        const res = await getStoreDataList(param);
        if (res.code === 200) {
          const dataList = res.rows || [];
          this.dataList = [ ...this.dataList, ...dataList ];
          this.isEmpty = this.dataList.length < 1;
          this.isFinish = res.total === this.dataList.length;
        }
      },
      dataSelect(data) {
        this.$emit('data-select', { data });
      },
      loadMore() {
        if (this.isFinish) {
          return;
        }
        this.pageData.pageNum += 1;
        this.getData();
      },
    },
  };
</script>

<style lang="scss" scoped>
  .store-list {
    &, * {
      box-sizing: border-box;
    }
    height: 100%;
    overflow: hidden;
    uni-scroll-view {
      height: 100%;
      
      .empty {
        text-align: center;
        color: #cccccc;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      
      /deep/ .uni-scroll-view-refresher {
        background-color: #f1f1f1 !important;
      }
      
      /deep/ .uni-swipe {
        border-bottom: 1px solid #f1f1f1;
      }
    }
  }
</style>
